package com.zzw.springboot.controller;

import com.zzw.springboot.annotation.Log;
import com.zzw.springboot.bean.SysRole;
import com.zzw.springboot.mapper.SysRoleMenuMapper;
import com.zzw.springboot.service.SysRoleService;
import com.zzw.springboot.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 角色菜单权限控制器
 */
@Api(tags = "角色菜单权限接口")
@RestController
@RequestMapping("/system/role-menu")
public class SysRoleMenuController {

    @Autowired
    private SysRoleMenuMapper roleMenuMapper;

    @Autowired
    private SysRoleService roleService;

    /**
     * 获取角色菜单ID列表
     */
    @ApiOperation("获取角色菜单ID列表")
    @GetMapping("/menuIds/{roleId}")
    public Result getMenuIdsByRoleId(@PathVariable Integer roleId) {
        List<Integer> menuIds = roleMenuMapper.selectMenuIdsByRoleId(roleId);
        return Result.success(menuIds);
    }

    /**
     * 修改角色菜单权限
     */
    @ApiOperation("修改角色菜单权限")
    @Log(module = "角色菜单权限", type = "修改", description = "修改角色菜单权限")
    @PutMapping
    public Result updateRoleMenu(@RequestBody SysRole role) {
        return Result.success(roleService.updateRole(role));
    }
}
